﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace MusicForMyBlog.App_Code
{
    class TrayApp : IDisposable
    {
        private NotifyIcon trayIcon;
        private ContextMenu trayMenu;
        public static MenuItem status,currentSong;

        public TrayApp()
        {
           
        }

        public void Start()
        {
            trayMenu = new ContextMenu();
            status = new MenuItem("");
            trayMenu.MenuItems.Add(status);

            currentSong = new MenuItem("Current Song");
            
            

            trayMenu.MenuItems.Add("Settings", OnSettings);
            trayMenu.MenuItems.Add("Exit", OnExit);

            trayIcon = new NotifyIcon();
            trayIcon.Text = "MusicForMyBlog";
            trayIcon.Icon = new Icon(SystemIcons.Shield, 40, 40);

            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible = true;
        }

        public void CreateStatusSubMenu()
        {
            status.MenuItems.Add(currentSong);
        }

        public void RemoveStatusSubMenu()
        {

            status.MenuItems.Remove(currentSong);
        }

        private void OnSettings(object sender, EventArgs e)
        {
            Settings frmSettings = new Settings();
            frmSettings.Show();
        }

        private void OnExit(object sender, EventArgs e)
        {
            Dispose();    
        }

        public void Dispose()
        {
            
            trayIcon.Dispose();
            trayMenu.Dispose();
            Application.Exit();
        }

        public string Status
        {
            get
            {
                return status.Text;
            }
            set
            {
                status.Text = value;
            }
        }

        public string CurrentSong
        {
            get
            {
                return currentSong.Text;
            }
            set
            {
                currentSong.Text = value;
            }

        }
    }
}
